package gare.vente;

import thread.Voyageur;

public class EspaceVente {
	
	private static int	NB_GUICHETS				= 1;
	
	private Guichet		lesGuichets[]			= new Guichet[NB_GUICHETS];
	
	public static int	TEMPS_IMPRESSION_TICKET	= 2000;
	
	private int			nbOcuppee				= 0;
	
	public EspaceVente() {
		for (int i = 0; i < NB_GUICHETS; i++)
			lesGuichets[i] = new Guichet(i);
	}
	
	public synchronized void accueillirVoyageur(Voyageur voyageur) {
		System.out.println(voyageur.toString() + " est en attente du service");
		while (nbOcuppee >= NB_GUICHETS) {
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
		for (Guichet guichet : lesGuichets) {
			if (guichet.estLibre())
				guichet.accueillir(voyageur);
		}
		
	}
	
	public void afficher() {
		System.out.println(">>>");
		for (Guichet guichet : lesGuichets) {
			guichet.afficher();
		}
		System.out.println("\n<<<");
	}
}
